﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Spore.Utils
{
   public class DTOTypeConverter
    {
       public static DTOTypeConverter Instance= new DTOTypeConverter();

       string registerFile;
       int key=0;
       Dictionary<int, Type> dic;


       public DTOTypeConverter():this(string.Empty)
       {
           dic = new Dictionary<int, Type>();
           this.RegType(typeof(QunYing.Model.UserLoginInfo));
       }

       private void RegType(Type type)
       {
           key++;
           dic.Add(key, type);
       }

       public DTOTypeConverter(string configFile)
       {
           this.dic = new Dictionary<int, Type>();
           this.registerFile = configFile;
           this.InitFormConfigFile();
           this.dic.Add(120, typeof(MyClass));
       }
       
       public virtual Type GetTypeByID(int id)
       {
           return dic[id];
       }

       public  bool RegisterType(int id,Type type)
       {
           if (!this.dic.Keys.Contains(id))
           {
               this.dic.Add(id, type);
               return true;
           }
           return false;
       }

       public virtual int GetIDbyType(Type type)
       {
           foreach (var v in dic)
           {
               if (v.Value == type)
                   return v.Key;
           }
           return -1;
       }

       private void InitFormConfigFile()
       {
           if (!string.IsNullOrEmpty(registerFile))
           {
               //Todo
           }
       }
    }
}
